import logging, time, os
import random
import sys
from faker import Faker

BASE_PATH = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
sys.path.append(BASE_PATH)

# 定义日志文件路径
LOG_PATH = os.path.join(BASE_PATH, "log")
if not os.path.exists(LOG_PATH):
  os.mkdir(LOG_PATH)


class UserAgent():
  '''
    随机生成常用的的user-agent
    '''

  def __init__(self):
    self.f = Faker()

  def chrome(self):
    '''
        随机生成Chrome的浏览器user_agent信息
        '''
    return self.f.chrome()

  def firefox(self):
    '''
        随机生成FireFox的浏览器user_agent信息
        '''
    return self.f.firefox()

  def internet_explorer(self):
    '''
        随机生成IE的浏览器user_agent信息
        '''
    return self.f.internet_explorer()

  def opera(self):
    '''
        随机生成Opera的浏览器user_agent信息
        '''
    return self.f.opera()

  def safari(self):
    '''
        随机生成Safari的浏览器user_agent信息
        '''
    return self.f.safari()

  def linux_platform_token(self):
    '''
        随机Linux信息
        '''
    return self.f.linux_platform_token()

  def user_agent(self):
    '''
        随机user_agent信息
        '''
    return self.f.user_agent()

  def get_user_agent_one(self):
    '''
        固定的一个user_agent,因为服务端会做校验
        '''
    user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.27 Safari/537.36"
    return user_agent

  def get_user_agent_nj(self):
    '''
        固定的一个user_agent,因为服务端会做校验
        '''
    user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36"
    return user_agent


useragent = UserAgent()


# if __name__ == '__main__':
# useragent = UserAgent()
# print(useragent.chrome())
# print(useragent.opera())
# print(useragent.safari())
# print(useragent.firefox())
# print(useragent.internet_explorer())
# print(useragent.linux_platform_token())
# print(useragent.user_agent())
# print(useragent.time())

